package com.woniuxy.JSP;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @auther linke
 * @create 2021-10-20 9:53
 * Servlet实现jsp页面输出
 */
@WebServlet("/jspDemo01")
public class JspDemo01 extends HttpServlet {
    /**
     * 通过域对象设置值并接收
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("jspDemo01...执行了");

        ServletContext servletContext = req.getServletContext();
        //设置属性
        servletContext.setAttribute("name","tom");
        //req.setAttribute("name","tom");
        //重定向
        resp.sendRedirect("/web03/JspDemo03.jsp");
        //req.getRequestDispatcher("/JspDemo03.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
